package commom.domain;

public class AjaxResult<T> {

    private final static int SUCCESS = 200;
    private final static int FAILED = 0;
    private final static String OK = "OK";

    //业务状态码，200-成功，其它-失败
    private int code;
    //响应消息
    private String msg;
    //响应数据
    private T data;

    public static AjaxResult<Void> ok() {
        return new AjaxResult<Void>(SUCCESS, OK, null);
    }

    public static <T> AjaxResult<T> ok(T data) {
        return new AjaxResult<>(SUCCESS, OK, data);
    }

    public static <T> AjaxResult<T> erroAjaxResult(String msg) {
        return new AjaxResult<>(FAILED, msg, null);
    }

    public static <T> AjaxResult<T> erroAjaxResult(int code, String msg) {
        return new AjaxResult<>(code, msg, null);
    }

    public AjaxResult() {
    }

    public AjaxResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public boolean success(){
        return code == SUCCESS;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
